import { defineStore } from 'pinia'
import { type appState } from '@/stores/initerface'

export const MUSIC_PLAYER = 'music-player'

export const useAppStore = defineStore('useApp', {
  state: (): appState => {
    return {
      playing: false, // 状态
      currentIndex: -1, // 索引
      dataList: [], // 列表
    }
  },
  getters: {
    data: (state) => {
      return state.dataList[state.currentIndex] || {}
    }
  },
  actions: {
    // 保存列表
    setDataList(dataList: any) {
      this.dataList = dataList
    },
    // 修改当前音乐索引
    setCurrentIndex(currentIndex: any) {
      this.currentIndex = currentIndex
    },
    // 状态
    setPlaying(playing: any) {
      this.playing = playing
    },
  },
  // 持久化
  persist: {
    key: MUSIC_PLAYER
  }

})
